package client.comm.baoding.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.comm.baoding.api.bean.BankBind
import client.comm.baoding.ui.viewmodel.MiddleVm
import client.comm.commlib.network.data.JsonResult
import kotlinx.coroutines.flow.*

class CreateRechargeViewModel(app: Application) : MiddleVm(app) {

    val isShowing = MutableLiveData<Boolean>(false)
    val num = MutableLiveData<String>()
    val okCall = MutableLiveData<JsonResult<BankBind>>()
    val txType = MutableLiveData<Int>(-1)

    fun checkYj() {
        txType.value = 1
    }

    /**
     * 绑 银行卡 充值
     */
    fun checkBank() {
        txType.value = 3
    }

    fun checkBank2() {
        txType.value = 4
    }

    fun ok() {
        this@CreateRechargeViewModel.isShowing.value = true
        hold({
            server.recharge_orders2(num.value!!, "${txType.value}")
        }, {
            isShowing.value = true
        }, success = {
            okCall.value = it
        }, complete = {
            isShowing.value = false
        })
    }


    fun ok3(linkId: String) {
        this@CreateRechargeViewModel.isShowing.value = true
        hold({
            server.recharge_orders3(num.value!!, "${txType.value}", linkId)
        }, {
            isShowing.value = true
        }, success = {
            okCall.value = it
        }, complete = {
            isShowing.value = false
        })
    }


}